//
//  HRFollowTopView.m
//  Hear
//
//  Created by mac on 2017/8/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRFollowTopView.h"
@interface HRFollowTopView ()
@property(nonatomic, strong)NSMutableArray *topViewArray;
@property(nonatomic, strong)UILabel *lineLabel;

@end
@implementation HRFollowTopView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        CGFloat leftPading = 40;
        
        CGFloat pading = 20;
        
        
        CGFloat blockWidth = (kFullWidth-leftPading*2-pading*2)/3;
        
        self.topViewArray = [NSMutableArray array];
        
        NSArray *descArr = @[@"我的好友",@"我的关注",@"关注我的"];
        
        for (int i = 0; i <3; i++) {
            
            UIButton *blockView = [UIButton new];
            [self addSubview:blockView];
            blockView.frame = CGRectMake(leftPading+i*(blockWidth+pading), 0, blockWidth, self.height);
            blockView.tag = i;
            [blockView addTarget:self action:@selector(targetButton:) forControlEvents:UIControlEventTouchUpInside];
            
            
            
            UILabel *numLabel = [UILabel new];
            numLabel.text = @"0";
            numLabel.font = CustomUIFont(14);
            numLabel.textColor = MainColor;
            [blockView  addSubview:numLabel];
            numLabel.textAlignment = 1;
            numLabel.frame = CGRectMake(0, 5, blockView.width, 20);
            [self.topViewArray addObject:numLabel];
            
            
            UILabel *descLabel = [UILabel new];
            descLabel.text = descArr[i];
            descLabel.font = CustomUIFont(14);
            descLabel.textColor = MainColor;
            [blockView  addSubview:descLabel];
            descLabel.textAlignment = 1;
            descLabel.frame = CGRectMake(numLabel.left, blockView.bottom-25, blockView.width, 20);
            
            
            if (i ==0){
                UILabel *lineLabel = [UILabel new];
                lineLabel.backgroundColor = MainColor;
                [self  addSubview:(self.lineLabel=lineLabel)];
                lineLabel.frame = CGRectMake(blockView.left, blockView.bottom-1, blockView.width, 1);
            }

        }
    }
    return self;
}

-(void)showPeopelCount:(NSInteger)count andIndex:(NSInteger)index{
    UILabel *numLabel = self.topViewArray[index];
    numLabel.text = [NSString stringWithFormat:@"%ld",(long)count];
}

- (void)targetButton:(UIButton *)button{
    
    
    WeakSelf
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.lineLabel.left = button.left;
    }];
    
    if (self.cutWithIndexBlock){
        self.cutWithIndexBlock(button.tag);
    }
    
}


@end
